package Operation;

import book.BookList;

import java.util.Scanner;

public class  DelOperation implements IOperation{
    @Override
    public void work(BookList books) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("删除图书！");
        System.out.println("输入想要删除的书: ");
        String name=scanner.next();
        int cur=books.getUserSize();
        for (int i = 0; i < cur; i++) {
            if(books.getBooks(i).getName().equals(name)) {
                for (int j = i; j < cur-1; j++) {
                    books.setBooks(books.getBooks(j+1),j);
                }
                books.setUserSize(cur-1);
                books.setBooks(null);
                System.out.println("删除成功");

            return;
            }
        }
        System.out.println("没有找到要删除的书 ");
    }
}
